package tr.edu.ozyegin.ccrg.raid.network;


import java.io.DataInputStream;
import java.io.IOException;

import tr.edu.ozyegin.ccrg.raid.config.ConfigManager;
import tr.edu.ozyegin.ccrg.raid.master.Master;

public class MasterTest {
	public static void main(String [] args){
		ConfigManager conf = ConfigManager.getInstance("conf" + System.getProperty("file.separator") + "master-site.xml");
		int port = 0;
		try{
			port = Integer.parseInt(conf.searchByKey("raid.master.port").getValue());
		}
		catch(Exception e){
			System.out.println("raid.master.port value is not correct in master-site.xml file");
		}
		
		System.out.println("application starting up!...");
		String quorum = conf.searchByKey("raid.master.quorum").getValue();
		Master test = new Master(quorum);
		System.out.println("test created!...");
		Server server  = new Server(port);
		System.out.println("accepting connections!...");
		if(quorum == null)return;
		String[] quorumList = quorum.split(",");
		server.Accept(test,quorumList.length);
		System.out.println("Quorum Started");
		try {
			DataInputStream di = new DataInputStream(System.in);
			for(;;){
				String line = di.readLine();
				if(line.equals("exit") || line.equals("Exit")) break;
				test.writeFile(line);
				//test.writeFile("conf\\gos-3.1-gadgets-20081205.iso");
			}
			test.CloseAll();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
